package com.ming.yourdiary.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkUtil {

  /*检查网络链接状态*/
  public static boolean isNetConnect(Context context) {
    if (context != null) {
      ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      if (connectivityManager == null) {
        return false;
      }

      NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
      if (networkInfo != null) {
        return networkInfo.isAvailable();
      }
    }
    return false;
  }

  /*检查wifi链接状态*/
  public static boolean isWifiConnected(Context context) {
    if (context != null) {
      ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(1);
      if (wifiNetworkInfo == null) {
        return wifiNetworkInfo.isAvailable();
      }
    }
    return false;
  }

}
